package com.pinxixi.file.controller;

import com.pinxixi.api.file.FileControllerApi;
import com.pinxixi.file.config.FastDFSClient;
import com.pinxixi.framework.model.response.CommonCode;
import com.pinxixi.framework.model.response.QueryResponseResult;
import com.pinxixi.framework.model.response.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file")
public class FileController implements FileControllerApi {

    @Autowired
    private FastDFSClient fdfsClient;

    @Override
    @PostMapping("/upload")
    public QueryResponseResult upload(MultipartFile file) {
        String url = "";
        try {
            url = fdfsClient.uploadFile(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  new QueryResponseResult(CommonCode.SUCCESS,url);
    }
}
